import React, { useEffect, useState } from 'react'
import { LeftOutline } from 'antd-mobile-icons'
import axios from 'axios'
import { useNavigate } from 'react-router-dom'
import { useDispatch } from "react-redux" 
import { xi } from "../../store/count"

export default function Login() {
  const [list,setlist] = useState([])
  let dispatch = useDispatch()
  let navigate = useNavigate()
  const userlist = async () => {
    let { data } = await axios.post('http://localhost:3000/jfq/login',{username:username,password:password})
    if(data.code==200){
      sessionStorage.setItem("data",JSON.stringify(data))
      navigate("/app/shouy")
      dispatch(xi(data.usedata))
    }
    console.log(data.usedata);

}
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');

  return (
    <div>
    <LeftOutline />
    <div>
        <p>登录注册</p>
        <p>未注册的手机号登录成功后将自动注册</p>
    </div>
    <div>
        <input type="text" placeholder='请输入用户名' onChange={(e) => setUsername(e.target.value)}/>
        <input type="text" placeholder='请输入密码' onChange={(e) => setPassword(e.target.value)}/>
    </div>
    <button onClick={()=>{
      userlist()
    }}>登录</button>
    <p>我以阅读并同意签署<span>用户协议</span>和<span>隐私政策</span></p>
    </div>
  )
}
